package com.petsdar.pojo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.petsdar.utils.Constant;
import com.petsdar.utils.JsonUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA
 * User: heroC
 * Date: 2020/7/2
 * Time: 10:58
 * Description: 封装消息返回数据
 * Version: V1.0
 */

@Component
public class Result implements Serializable {
    private static final long serialVersionUID = 70210581130L;
    private Logger log = Logger.getLogger(Result.class);
    /** json数据转换工具 */
    private ObjectMapper objectMapper = new ObjectMapper();
    /** 返回的结果 */
    String result = Constant.RESULT_SERVICE_EX;
    /** 返回的状态码 */
    private String statusCode;
    /** 返回的信息 */
    private String msg;
    /** 返回的数据 */
    private Object data;

    public Result() {
    }

    public Result(String statusCode, String msg) {
        this.statusCode = statusCode;
        this.msg = msg;
    }

    public String getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(String statusCode) {
        this.statusCode = statusCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("statusCode",getStatusCode());
        map.put("msg",getMsg());
        if (data != null){
            map.put("data",getData());
        }
        result = JsonUtil.toJson(map,Result.class);
        return result;
    }
}
